package MainService;

/**
 * Created by ghost461 on 17-6-28.
 */
import PartService.*;
import RedisService.*;

public class ThreadForInsert implements Runnable{
    int num = 1;
    private Thread t;
   private String threadName;

   ThreadForInsert( String name) {
       threadName = name;
       System.out.println("Creating " +  threadName );
   }

   public void run() {
      System.out.println("Running " +  threadName );
      while(true){
    	  System.out.println("10");
          //创建并开启端口监听器
          PartListener partListener = new PartListener();
          partListener.updateInfomation();
          System.out.println("11");
          //输出接收到的json数据
          System.out.println(partListener.getInformation());
          //关闭端口监听器
          partListener.close();
          //调整json格式，删除前面那一段，并由StringBuilder转换为String
          String information = partListener.getInformation().delete(0, 174).toString();
          System.out.println("输入监听数据是:");
          System.out.println(information);
          //输出转换后的json数据
          //System.out.println(information);
          RedisCURD redis = new RedisCURD();
          
          redis.insert(num,information);
          num++;
      }
   }

   public void start () {
      System.out.println("Starting " +  threadName );
      if (t == null) {
         t = new Thread (this, threadName);
         t.start ();
      }
   }
}

